<template>
  <!-- 添加或修改项目基础信息管理对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body v-dialogDrag width="90%">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="98px">
      <el-form-item label="框架编号" prop="projectCode">
        <el-input @keyup.enter.native="handleQuery" clearable style="width: 240px;"
                  placeholder="请输入框架编号" v-model="queryParams.projectCode"/>
      </el-form-item>
      <el-form-item label="订单编号" prop="code">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入订单编号" v-model="queryParams.code"/>
      </el-form-item>
      <el-form-item label="业务员" prop="salesman">
        <el-select v-model="queryParams.salesmanId" placeholder="请选择业务员" filterable clearable
                   style="width: 100%">
          <el-option v-for="item in salesmanList"
                     :key="item.userId" :label="item.nickName" :value="item.userId"/>
        </el-select>
      </el-form-item>
      <el-form-item label="买方名称" prop="customName">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入买方名称" v-model="queryParams.customName"/>
      </el-form-item>

      <el-form-item label="制单人" prop="createName">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入制单人" v-model="queryParams.createName"/>
      </el-form-item>
      <el-form-item label="下单日期" prop="orderDate">
        <el-date-picker clearable v-model="queryParams.params['orderDate']" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择下单日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目状态" prop="status">
        <el-select clearable placeholder="请选择项目状态" style="width: 200px" v-model="queryParams.status">
          <el-option :key="dict.value"
                     :label="dict.label" :value="dict.value" v-for="dict in dict.type.pro_status"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading">
        <el-table-column align="center" label="序号" type="index" width="50">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
      <el-table-column align="center" label="框架编号" prop="projectCode"/>
      <el-table-column align="center" label="订单编号" prop="code">
        <template slot-scope="scope">
          <el-tooltip class="item" content="点击查看详情" effect="dark" placement="left-start">
            <span @click="handleUpdateDetail(scope.row)"
                  style="color: #00afff;cursor:pointer;">{{ scope.row.code}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column align="center" label="需求日期"  prop="deliveryTime"/>
      <el-table-column align="center" label="买方" prop="customName"/>
      <el-table-column align="center" label="业务员" prop="salesmanName"/>
      <el-table-column align="center" label="制单人" prop="createName"/>
      <el-table-column align="center" label="项目状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pro_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="地区" prop="area">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_area" :value="scope.row.area"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="订单金额" prop="contractMoney"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="300"
                       v-if="this.queryParams.params.dataFlag !=1 && this.queryParams.params.dataFlag!=2 && this.queryParams.params.dataFlag!=3">
        <template slot-scope="scope">
          <el-button @click="fenpeiNew(scope.row)" icon="el-icon-plus" size="mini" type="text">
            分配任务
          </el-button>
          <el-button @click="GongxuGoodsNew(scope.row)" icon="el-icon-plus" size="mini" type="text">
            工序选择
          </el-button>
          <el-button @click="ChoseGoodsNew(scope.row)" icon="el-icon-plus" size="mini" type="text">
            产品选择
          </el-button>
          <el-button @click="shedinggongxu(scope.row)" icon="el-icon-view" size="mini" type="text">
            订单产品
          </el-button>
          <!--<el-button @click="disassemble(scope.row)" icon="el-icon-folder-add" size="mini" type="text"
                     v-if="scope.row.goodsType==='1'">
            铁件拆解
          </el-button>-->
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['develop:ProjectBaseInfo:edit']">修改
          </el-button>
          <el-popconfirm :title="`确认删除 `+scope.row.code+` 数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete" v-if="scope.row.status==='0'"
                       v-hasPermi="['develop:ProjectBaseInfo:remove']">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <pagination :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
    @pagination="getList" v-show="total>0"/>
    <process-list ref="processlist"></Process-list>
    <allocating-task ref="allocatingtask"></allocating-task>
    <allGoodsForm-List ref="allGoodsForm"></allGoodsForm-List>
    <goodsChoseForm-list ref="goodsChoseForm"></goodsChoseForm-list>
    <projectBaseInfo-form @ok="getList" ref="form"></projectBaseInfo-form>

    <choseGx-form @ok="getList" ref="choseGxForm"></choseGx-form>
    <chajie-form @ok="getList" ref="chaijieForm"></chajie-form>
    <fpTaskForm-list @ok="getList" ref="taskFpForm"></fpTaskForm-list>
    <xunjian-form @ok="getList" ref="xunjianForm"></xunjian-form>

    <div class="dialog-footer" slot="footer">
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>

    import {addAction,deleteAction, getAction, getById} from '@/api/manage'
    import ChoseGxForm from "./ChoseGxForm";
    import ChajieForm from "./ChajieForm";
    import FpTaskFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/FpTaskFormList";
    import XunjianForm from "@/views/develop/projectBaseInfo/prjForGoodsIn/XunjianForm";

    import AllocatingTask from "@/views/develop/process/AllocatingTask";
    import ProcessList from "@/views/develop/process/ProcessList";
    import AllGoodsFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/AllGoodsFormList";
    import GoodsChoseFormList from "@/views/develop/projectBaseInfo/prjForGoodsIn/GoodsChoseFormList";
    import ProjectBaseInfoForm from '@/views/develop/projectBaseInfo/module/ProjectBaseInfoForm'

    export default {
        name: "XiaoshoudanFormList",
        dicts: ['yes_no', 'fund_callback', 'fund_status', 'tax_status', 'pro_status','order_area'],
        components: {
          ChoseGxForm,
          ChajieForm,
          FpTaskFormList,
          XunjianForm,
          AllocatingTask,
          ProcessList,
          AllGoodsFormList,
          GoodsChoseFormList,
          ProjectBaseInfoForm
        },
        data() {
            return {
              salesmanList: [],
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "销售订单明细",
                // 是否显示弹出层
                open: false,
                // 显示搜索条件
                showSearch: true,
                // 表单参数
                form: {},
                projectId: "",
                proStatus: "",
                columns: [],
                total: 0,
                // 表单校验
                rules: {
                },
                queryParams: {
                  yearStr: null,
                  pageNum: 1,
                  pageSize: 10,
                  name: null,
                  code: null,
                  master: null,
                  customId: null,
                  projectCode: null,
                  customName: null,
                  companyName: null,
                  contractDate: null,
                  contractMoney: null,
                  auditMoney: null,
                  checkDate: null,
                  checkState: null,
                  fundCallback: null,
                  information: null,
                  orderByColumn: "create_time",
                  isAsc: "desc",
                  params: {},
                },
                url: {
                    list: '/projectBaseInfo/projectBaseInfo/list',
                    getById: '/projectBaseInfo/projectBaseInfo/',
                    salesmanList: '/system/role/authUser/allocatedList',
                },
            };
        },
        created() {
          this.handleQuery();
        },
        methods: {
          getSalesmanList(){
      getAction(this.url.salesmanList,{"roleId":"e1c2bca31b7944e98f79008c726cf7e8"}).then(response => {
        this.salesmanList = response.rows;
      });
    },
          fenpeiNew(row) {
            this.$refs.allocatingtask.handleUpdate(row);
          },
          // 工序选择
          GongxuGoodsNew(row) {
            this.$refs.processlist.handleUpdate(row);
          },
          ChoseGoodsNew(row) {
            this.$refs.goodsChoseForm.handleUpdate(row);
          },
          shedinggongxu(row) {
            this.$refs.allGoodsForm.shedingGygx(row);
          },

            xunjian(row){
              this.$refs.xunjianForm.xunjianShow(row);
            },
            taskFp(row){
              this.$refs.taskFpForm.taskFpShow(row);
            },
            chaijie(row){
              this.$refs.chaijieForm.chaijieGoods(row);
            },
            choseGy(row){
              this.$refs.choseGxForm.choseGy(row);
            },
            show(row){
              this.open = true;
              this.projectId=row.id;
              this.getList();
            },
            getList() {
                this.loading = true;
                this.queryParams.projectId = this.projectId;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.columns = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
              this.queryParams.pageNum = 1;
              this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
              this.resetForm("queryForm");
              this.handleQuery();
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
          reset() {
            this.form = {
              id: null,
              remark: null,
              delFlag: null,
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null
            };
            this.resetForm("form");
          },
          handleUpdate(row) {
            this.$refs.form.handleUpdate(row);
          },
            /*handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                this.proId = id;
                this.proStatus = row.status;
                getById(this.url.getById, id).then(response => {
                    this.open = true;
                    this.title = "修改订单基础信息管理";
                    this.getList();
                });
            },*/
        }
    };
</script>
